package com.ocean.web.controller.product;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ocean.common.annotation.Log;
import com.ocean.common.enums.BusinessType;
import com.ocean.productDict.domain.OFrequency;
import com.ocean.productDict.service.IOFrequencyService;
import com.ocean.common.core.controller.BaseController;
import com.ocean.common.core.domain.AjaxResult;
import com.ocean.common.utils.poi.ExcelUtil;
import com.ocean.common.core.page.TableDataInfo;

/**
 * 起报时间维护Controller
 *
 * @author ocean
 * @date 2023-01-04
 */
@Controller
@RequestMapping("/product/frequency")
public class OFrequencyController extends BaseController
{
    private String prefix = "product/frequency";

    @Autowired
    private IOFrequencyService oFrequencyService;

    //@RequiresPermissions("product:frequency:view")
    @GetMapping()
    public String frequency()
    {
        return prefix + "/list";
    }

    /**
     * 查询起报时间维护列表
     */
    //@RequiresPermissions("product:frequency:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OFrequency oFrequency)
    {
        startPage();
        List<OFrequency> list = oFrequencyService.selectOFrequencyList(oFrequency);
        return getDataTable(list);
    }

    /**
     * 导出起报时间维护列表
     */
    //@RequiresPermissions("product:frequency:export")
    @Log(title = "起报时间维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OFrequency oFrequency)
    {
        List<OFrequency> list = oFrequencyService.selectOFrequencyList(oFrequency);
        ExcelUtil<OFrequency> util = new ExcelUtil<OFrequency>(OFrequency.class);
        return util.exportExcel(list, "起报时间维护数据");
    }

    /**
     * 新增起报时间维护
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        Map<String,List> map = oFrequencyService.getNameAndCode();
        mmap.putAll(map);
        return prefix + "/add";
    }

    /**
     * 新增保存起报时间维护
     */
    //@RequiresPermissions("product:frequency:add")
    @Log(title = "起报时间维护", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OFrequency oFrequency)
    {
        return toAjax(oFrequencyService.insertOFrequency(oFrequency));
    }

    /**
     * 修改起报时间维护
     */
    //@RequiresPermissions("product:frequency:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OFrequency oFrequency = oFrequencyService.selectOFrequencyById(id);
        mmap.put("oFrequency", oFrequency);
        Map<String,List> map = oFrequencyService.getNameAndCode();
        mmap.putAll(map);
        return prefix + "/edit";
    }

    /**
     * 修改保存起报时间维护
     */
    //@RequiresPermissions("product:frequency:edit")
    @Log(title = "起报时间维护", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OFrequency oFrequency)
    {
        return toAjax(oFrequencyService.updateOFrequency(oFrequency));
    }

    /**
     * 删除起报时间维护
     */
    //@RequiresPermissions("product:frequency:remove")
    @Log(title = "起报时间维护", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(oFrequencyService.deleteOFrequencyByIds(ids));
    }

    /**
     * 修改起报时间维护
     */
    //@RequiresPermissions("product:frequency:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        OFrequency oFrequency = oFrequencyService.selectOFrequencyById(id);
        mmap.put("oFrequency", oFrequency);
        return prefix + "/detail";
    }
}
